package com.example.movie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.movie.domain.R;
import com.example.movie.service.CommentService;
import com.example.movie.domain.Comment;
import com.example.movie.mapper.CommentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author HuRan
* @description 针对表【comment(评论表，用于存储用户对电影的评论信息)】的数据库操作Service实现
* @createDate 2024-10-24 11:09:25
*/
@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> implements CommentService {

    @Autowired
    CommentMapper commentMapper;

    @Override
    public List<Comment> getCommentsByMId(Long mId) {
        QueryWrapper<Comment> qw = new QueryWrapper<>();
        qw.eq("c_mid",mId);
        List<Comment> comments = this.list(qw);
        return comments;
    }

    @Override
    public List<Comment> getComments(Integer movieId, Long currentPage, Long pageSize) {
        LambdaQueryWrapper<Comment> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Comment::getMovieId,movieId);
        Page<Comment> page = new Page<>(currentPage,pageSize);
        Page<Comment> commentPage = this.page(page,queryWrapper);
        return commentPage.getRecords();
    }
}




